<?php

/*
 * 权限组模块操作类
 */
class osgh_admin_module_group_tbl_cls extends pl_db_opt_cls
{	
	/*
	 * 构造函数
	 */
	public function __construct()
	{
		global $_db_name;
		$this->setDbName($_db_name);
		$this->setTblName('osgh_admin_module_group_tbl');
	}
	
	/*
	 * 给权限组添加模块
	 *
	 * @param array $data
	 * @return int
	 */
	public function addAdminModuleGroup($data)
	{
		return $this->insert($data, 'IGNORE');
	}
	
	/*
	 * 删除权限组模块
	 *
	 * @param array $module_id
	 * @return bool
	 */
	public function delAdminModuleGroup($group_id = 0, $module_id = 0)
	{
		$group_id = intval($group_id);
		$module_id = intval($module_id);
		if($group_id < 1 && $module_id < 1) return false;
		
		$where_str = '';
		if($group_id > 0)
		{
			$where_str .= "group_id='{$group_id}'";
		}
		if($module_id > 0) 
		{
			if(strlen($where_str) > 0) $where_str .= ' AND ';
			$where_str .= "module_id='{$module_id}'";
		}

		return $this -> delete($where_str);
	}
	
	/**
	 * 获取权限组模块列表
	 * 
	 * @param bool $b_select_count
	 * @param string $where_str    查询条件
	 * @param string $order_by
	 * @param string $limit
	 * @return array
	 */
	public function getAdminModuleGroupList($b_select_count = false, $where_str = '', $order_by = '', $limit = '')
	{
		$sql = "SELECT module_id FROM {$this->db_name}.{$this->tbl_name}";
		
		$sql_where = '';
		$sql_where_sp = '';
		
		if( strlen($where_str) > 0 )
		{
			$sql_where_sp = strlen($sql_where)>0?' AND ':'';
			$sql_where = $sql_where . $sql_where_sp . $where_str;
		}
		
		if ( strlen($sql_where) > 0 )
		{
			$sql .= " WHERE " . $sql_where;
		}
		
		if ( $b_select_count == true )
		{
			//统计记录数
			$tmp = $this->getList($b_select_count, $sql);
			return $tmp;
		}	
		
		return $this->getList($b_select_count, $sql, $order_by, $limit);
		
	}
}

?>